import { db } from "../cloudInit.js";
const _ = db.command;
import Query from "@/utils/Query.js";
export const auditXinCards = new Query({
    async $getPage(index) {
        const UnPublicData = db.collection("UnPublicXin");
        const num = 5;
        if (index === 0) {
            const { total } = await UnPublicData.count();
            this.total = Math.ceil(total / num);
        }
        return UnPublicData.skip(index * num)
            .limit(num)
            .get()
            .then(({ data }) => {
                console.log(data);
                return data;
            });
    },
});
export const UserResult = new Query({
    $init() {
        console.log("UserResult 切换到 temp 分支", this);
        this.$checkout("temp");
    },
    $lock: false,
    total: 0,
    query: "",
    search(keyword) {
        this.query = keyword;
        this.$AllPages.clear();
        return this.$to(0);
    },

    async $getPage(index) {
        if (!this.query) throw "搜索内容不能为空";
        const gen = new db.RegExp({
            regexp: this.query,
            options: "i",
        });

        const Querying = db.collection("User").where(
            _.or([
                {
                    appId: gen,
                },
                {
                    nickName: gen,
                },
            ])
        );

        const num = 15;
        if (index === 0) {
            const { total } = await Querying.count();
            this.total = Math.ceil(total / num);
        }
        return Querying.skip(index * num)
            .limit(num)
            .get()
            .then(({ data }) => {
                console.log(data);
                return data;
            });
    },
});
export const ManageFeedback = new Query({
    // default 分支认为是没有
    change(tag) {
        const target = tag
            ? tag
            : this.$branch === "default"
            ? "notDone"
            : "default";
        this.$checkout(target);
    },
    async $getPage(index) {
        const Querying = db
            .collection("Feedback")
            .orderBy("createTime", "desc")
            .where({
                isDone: this.$branch !== "default",
            });
        const num = 10;
        if (index === 0) {
            const { total } = await Querying.count();
            this.total = Math.ceil(total / num);
        }
        return Querying.skip(index * num)
            .limit(num)
            .get()
            .then(({ data }) => {
                console.log(data);
                return data;
            });
    },
});
